# 正确使用beautifulsoup或xpath爬取数据

from bs4 import BeautifulSoup
import requests

try:
    req = requests.get(url, headers=ua)
    req.encoding = "utf-8"
    soup = BeautifulSoup(req.text, "html,parser")
except:
    print("网络地址错误或网络信号不佳")

divs = soup.findAll("dov",{"class": "land-recruit-card_3pAuc"})

def get_data():
    pass

url = 'https://www.kanzhun.com/rank_p/?ka=index-icon-click'

ua = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36'
}
bianma = "utf-8"
get_soup(url, ua, bianma)

h = ["岗位","薪资","工作经验","学历","公司联系人","联系人职位","公司名称","公司类型","员工人数","上市情况"]


for div in divs:
    # 岗位
    occupation = div.find("a", {"class": "job-title"})
    print("岗位" + occupation)
    # 薪资
    salari = div.find("div", {"class": "salary-info"}).text
    print("薪资" + salari)
    # 工作经验
    job_experience = div.find("a", {"class": "boss-tag grey"})[0].text
    print("工作经验" + job_experience)
    # 学历
    xueli = div.find("a", {"class": "boss-tag grey"})[1].text
    print("学历" + xueli)
    # 公司联系人
    contact = div.find("a", {"class": "boss-tag border none"}).span.text.palit("｜")
    print("公司联系人" + contact[0])
    # 联系人职位
    print("联系人职位：" + contact[1])
    # 公司名称
    company_title = div.find("div", {"class":"info-text"}).h3.text
    print("公司名称：" + company_title)
    # 公司类型
    company_type = div.find("div", {"class":"boss-tag border"})[0].text
    print("公司类型：" + company_type[0].text)
    # 员工人数
    print("员工人数：" + company_type[1].text)

    # 上市情况
    print("上市情况：" + company_type[2].text)

    print("---------------------------------")